package top.mataiji.manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.mataiji.manager.pojo.SlideShow;
import top.mataiji.manager.mapper.SlideShowMapper;
import top.mataiji.manager.pojo.SlideShowExample;
import top.mataiji.manager.service.SlideShowService;
import top.mataiji.manager.util.Common;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: zhaoss
 * @Date: 2021/4/4 - 04 - 04 - 21:00
 * @Description: top.mataiji.manager.service.impl
 * @version: 1.0
 */
@Service
public class SlideShowServiceImpl implements SlideShowService {

    @Autowired
    SlideShowMapper slideShowMapper;

    /**
     * 查询轮播图
     * @return
     */
    @Override
    public List<SlideShow> selectSlideShow() {
        return slideShowMapper.selectByExample(new SlideShowExample());
    }

    /**
     * 添加轮播图
     * @param imgs 图片地址
     * @return
     */
    @Override
    public int addSlideShow(List<String> imgs) {
        int count = 0;
        SlideShow slideShow = new SlideShow();
        for (int i = 0; i < imgs.size(); i++) {
            slideShow.setImgId(Common.getOrderId());
            slideShow.setImgAddress(imgs.get(i));
            slideShow.setDate(new Timestamp(System.currentTimeMillis()));
            count += slideShowMapper.insertSelective(slideShow);
        }
        return count;
    }

    @Override
    public int delectSlideShowById(Integer id) {
        return slideShowMapper.deleteByPrimaryKey(id);
    }


}
